import 'package:flutter/material.dart';
import 'package:flutter_widget_from_html_core/flutter_widget_from_html_core.dart';
import 'package:get/get.dart';
import 'package:ichinesereader/exam/ExamQuestionIndexPage.dart';
import 'package:ichinesereader/exam/dto/assessment.response.dart';
import 'package:ichinesereader/utils/log.dart';

import 'PlaceController.dart';
import 'PlacePlayerWidget.dart';

// ignore: must_be_immutable
class PlaceStepThreeTopic extends GetView<PlaceController> {
  UiQuestionStepTopic questionStepTopic;

  PlaceStepThreeTopic({Key? key, required this.questionStepTopic})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.all(10),
      child: _buildExamTopicContent(context),
    );
  }

  Widget _buildExamTopicContent(BuildContext context) {
    // return Obx(() {
    var head = questionStepTopic.head;
    String show = head?.show ?? '';
    String headText = head?.text ?? '';
    Log.debug('ExamTopicPage _buildExamTopicContent');
    Log.debug('ExamTopicPage questionStepTopic ${head?.toJson()}');
    List<Widget> examQuestionContents = [];
    if (show.contains(QuestionContent.QUESTION_SHOW_TYPE_TEXT)) {
      examQuestionContents.add(HtmlWidget(headText.replaceAll('\n', '<br/>'),
          textStyle: TextStyle(
              fontSize: 18,
              color: (Get.isDarkMode ? Color(0xFF757575) : Colors.black87),
              height: 1.8,
              wordSpacing: 1.5)));
    }
    if (show.contains(QuestionContent.QUESTION_SHOW_TYPE_AUDIO)) {
      examQuestionContents
          .add(PlacePlayerWidget(audioUrl: head?.audio ?? '', iconSize: 50));
    }
    if (show.contains(QuestionContent.QUESTION_SHOW_TYPE_IMAGE)) {
      examQuestionContents.add(Container(
          padding: const EdgeInsets.only(top: 10),
          width: (MediaQuery.of(context).size.width - 80) * 0.5 > 400
              ? 400
              : (MediaQuery.of(context).size.width - 80) * 0.5,
          child: Image.network(head?.image ?? '')));
    }

    Widget examQuestion = Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: examQuestionContents,
    );
    return examQuestion;
    // });
  }
}
